增加日志调试

chengzhenyu 7 年之前
父節點
當前提交
1e09979510
共有 2 個文件被更改,包括 10 次插入8 次删除
  1. 9 8
      app/src/main/java/ai/pai/lensman/App.java
  2. 1 0
      app/src/main/res/values/strings.xml

+ 9 - 8
app/src/main/java/ai/pai/lensman/App.java

@@ -41,7 +41,7 @@ public class App extends Application{
41 41
         super.onCreate();
42 42
         mInstance = this.getApplicationContext();
43 43
         if(!checkUsbPermission()){
44
-            Toast.makeText(this,"申请usb权限失败",Toast.LENGTH_SHORT).show();
44
+            Toast.makeText(this,R.string.usb_permission_denied,Toast.LENGTH_SHORT).show();
45 45
         }
46 46
         checkCameraLibs();
47 47
         initImageLoader();
@@ -50,6 +50,7 @@ public class App extends Application{
50 50
     }
51 51
 
52 52
     private boolean checkUsbPermission(){
53
+        LogHelper.d("czy","checkUsbPermission starts");
53 54
         Process process = null;
54 55
         DataOutputStream os = null;
55 56
         try {
@@ -57,7 +58,7 @@ public class App extends Application{
57 58
             String cmd1 = "setenforce 0";
58 59
             String cmd2 = "chmod -R 0777 /dev/bus/usb" ;
59 60
 
60
-            process = Runtime.getRuntime().exec("su"); // 切换到root帐号
61
+            process = Runtime.getRuntime().exec("su");
61 62
             os = new DataOutputStream(process.getOutputStream());
62 63
             os.writeBytes(cmd + "\n");
63 64
             os.writeBytes(cmd1 + "\n");
@@ -67,6 +68,7 @@ public class App extends Application{
67 68
             process.waitFor();
68 69
             return true;
69 70
         } catch (Exception e) {
71
+            LogHelper.d("czy","checkUsbPermission exception occur -->"+e);
70 72
             return false;
71 73
         } finally {
72 74
             try {
@@ -79,13 +81,14 @@ public class App extends Application{
79 81
         }
80 82
     }
81 83
 
82
-    public void copyResToSdcard(String name){
84
+    public void copyRawLibToSdcard(String dirPath){
85
+        LogHelper.d("czy","copyRawLibToSdcard");
83 86
         Field[] raw = R.raw.class.getFields();
84 87
         for (Field r : raw) {
85 88
             try {
86 89
                 int id=getResources().getIdentifier(r.getName(), "raw", getPackageName());
87 90
                 if(r.getName().startsWith("camera")){
88
-                    String path=name+"/"+r.getName()+".so";
91
+                    String path=dirPath+"/"+r.getName()+".so";
89 92
                     BufferedOutputStream rawZipWriter = new BufferedOutputStream((new FileOutputStream(new File(path))));
90 93
                     BufferedInputStream rawZipReader = new BufferedInputStream(getResources().openRawResource(id));
91 94
                     byte[] buff = new byte[20*1024];
@@ -98,6 +101,7 @@ public class App extends Application{
98 101
                     rawZipReader.close();
99 102
                 }
100 103
             } catch (Exception e) {
104
+                LogHelper.d("czy","copyRawLibToSdcard exception occur -->"+e);
101 105
                 e.printStackTrace();
102 106
             }
103 107
         }
@@ -111,7 +115,7 @@ public class App extends Application{
111 115
         String tmpLibDirPath = "/mnt/sdcard/lensman";
112 116
         File file = new File(tmpLibDirPath);
113 117
         file.mkdirs();
114
-        copyResToSdcard(tmpLibDirPath);
118
+        copyRawLibToSdcard(tmpLibDirPath);
115 119
         final String unzipPath = tmpLibDirPath+File.separator+"so";
116 120
         new File(unzipPath).mkdirs();
117 121
         new FileUnzipTask(tmpLibDirPath + File.separator + "camera.so", unzipPath, new FileUnzipTask.FileUnzipListener() {
@@ -189,7 +193,6 @@ public class App extends Application{
189 193
         if (dir.isDirectory()) {
190 194
             String[] children = dir.list();
191 195
             if (children != null) {
192
-                // 递归删除目录中的子目录下
193 196
                 for (int i = 0; i < children.length; i++) {
194 197
                     boolean success = deleteDir(new File(dir, children[i]));
195 198
                     if (!success) {
@@ -197,12 +200,10 @@ public class App extends Application{
197 200
                     }
198 201
                 }
199 202
             }
200
-
201 203
         }
202 204
         if (!dir.canRead() || !dir.canWrite()) {
203 205
             return false;
204 206
         }
205
-        // 目录此时为空,可以删除
206 207
         return dir.delete();
207 208
     }
208 209
 

+ 1 - 0
app/src/main/res/values/strings.xml

@@ -140,4 +140,5 @@
140 140
 
141 141
     <string name="session_photo_limit">只显示最近200张照片,您可以到存储卡目录查看更多</string>
142 142
 
143
+    <string name="usb_permission_denied">请检查设备是否已开放root权限</string>
143 144
 </resources>